package com.iflytek.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Alabama	452734	7340
 */
public class CovidSortSumMapper extends Mapper<LongWritable, Text, CovidCountBean2,Text> {

    CovidCountBean2 outKey = new CovidCountBean2();
    Text outValue = new Text();

    /**
     * 重写map父类方法：map回车
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        /**
         * 读取一行数据进行切割
         */
        String[] fields = value.toString().split("\t");
        /**
         * 提取数据 州、确诊数、死亡数
         */
        outKey.setCases(Long.parseLong(fields[1]));
        outKey.setDeaths(Long.parseLong(fields[2]));
        /**
         * outKey.set(Long.parseLong(fields[1]),Long.parseLong(fields[2]));
         */

        outValue.set(fields[0]);
        // 输出结果
        context.write(outKey,outValue);
    }
}